/*
 * jxController Project (2014)
 * 
 * by Denilson Edinaldo Pinto
 * 
 * LGPL
 * Copyright (C) 2014
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.jxController.view;

import java.awt.Frame;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import org.jxDao.dao.Dao;
import org.jxDao.dao.Persistable;
import org.jxDao.dao.filter.Filterable;
import org.jxSwing.i18n.I18N;

/**
 * @author Denilson Edinaldo Pinto
 * @porject jxController
 * @package org.jxController.view
 * @date 26/06/2014 - 20:41:43
 * @param <Bean>
 * @param <TDao>
 */
public abstract class FindDialog<Bean extends Persistable, TDao extends Dao<Bean>> extends FilterDialog<Bean, TDao> {
	
	private static final long serialVersionUID = 2091474256887804637L;
	
	/**
	 * @param owner
	 * @param title
	 * @param dao
	 * @param fetch
	 */
	public FindDialog(final Frame owner, final String title, final TDao dao, final Class<?>... fetch) {
	
		this(owner, title, dao, null, fetch);
	}
	
	/**
	 * @param owner
	 * @param title
	 * @param dao
	 * @param filter
	 * @param fetch
	 */
	public FindDialog(final Frame owner, final String title, final TDao dao, final Filterable filter, final Class<?>... fetch) {
	
		super(owner, I18N.component().search() + " - " + title, dao, filter, fetch);
		
		getTblRecords().setVisibleFilter(false);
		getTblRecords().setVisibleExport(false);
		getTblRecords().setVisiblePrint(false);
		
		getTblRecords().getTable().addMouseListener(new MouseAdapter() {
			
			@Override
			public void mouseClicked(final MouseEvent mouseEvent) {
			
				//
				if(mouseEvent.getClickCount() == 2) {
					
					selectedBeanAction(getTblRecords().getSelectedBean());
					
					dispose();
				}
			}
		});
		
		centralize();
	}
	
	/**
	 * @param enabled
	 */
	@Override
	protected void enabledFields(final boolean enabled) {
	
		super.enabledFields(enabled);
		
		getTblRecords().setEnabledFilter(enabled);
	}
	
	/**
	 * @param selectedBean
	 */
	public abstract void selectedBeanAction(Bean selectedBean);
}
